
class LocalStorage {
    static tokenKey = 'bgkdeliveryapptoken'
    static prefixKey = 'bgkdeliveryappprefix'

    /**
     * 获取本地Token
     */
    static getToken() {
        //需要返回promise可调用functions.ts中的promise
        try {
            return uni.getStorageSync(LocalStorage.tokenKey)
        } catch (error) {
            return false
        }
    };

    /**
     * 设置存储本地Token
     */
    static setToken(data : string | null) {
        //需要返回promise可调用functions.ts中的promise
        try {
            uni.setStorageSync(LocalStorage.tokenKey, data)
            return true
        } catch (error : any) {
            return false
        }
    }

    /**
     * 移除本地Token
     */
    static removeToken() {
        //需要返回promise可调用functions.ts中的promise
        try {
            uni.removeStorageSync(LocalStorage.tokenKey)
            return true
        } catch (error : any) {
            return false
        }
    }
    /**
     * 获取本地值
     */
    static get(key : string) {
        //需要返回promise可调用functions.ts中的promise
        try {
            return uni.getStorageSync(LocalStorage.prefixKey + key)
        } catch (error) {
            return false
        }
    };

    /**
     * 设置存储本地值
     */
    static set(key : string, data : any) {
        //需要返回promise可调用functions.ts中的promise
        try {
            uni.setStorageSync(LocalStorage.prefixKey + key, data)
            return true
        } catch (error : any) {
            return false
        }
    }

    /**
     * 移除本地值
     */
    static remove(key : string) {
        //需要返回promise可调用functions.ts中的promise
        try {
            uni.removeStorageSync(LocalStorage.prefixKey + key)
            return true
        } catch (error : any) {
            return false
        }
    }

    /**
     * 清除缓存
     */
    static clear(isSync : boolean = false) {
        if (isSync) {
            uni.clearStorageSync()
        } else {
            uni.clearStorage()
        }
    }
}

export default LocalStorage